<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">
            <el-form-item label="设备名称" prop="name">
                <el-input v-model="queryParams.name" placeholder="请输入设备名称"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="设备编码" prop="code">
                <el-input v-model="queryParams.code" placeholder="请输入设备编码"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="设备品牌" prop="pinpai">
                <el-input v-model="queryParams.pinpai" placeholder="请输入设备品牌"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="型号" prop="xinghao">
                <el-input v-model="queryParams.xinghao" placeholder="请输入型号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="所属部门" prop="haveHouse">
                <el-input v-model="queryParams.haveHouse" placeholder="请输入所属部门"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="审核人" prop="shenheName">
                <el-input v-model="queryParams.shenheName" placeholder="请输入审核人"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="使用部门" prop="useDept">
                <el-input v-model="queryParams.useDept" placeholder="请输入使用部门"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="故障问题" prop="problem">
                <el-input v-model="queryParams.problem" placeholder="请输入故障问题"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="维保内容" prop="maintenance">
                <el-input v-model="queryParams.maintenance" placeholder="请输入维保内容"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
          <el-form-item label="维保时间" prop="date">
            <el-date-picker clearable v-model="queryParams.date"
                            type="date" value-format="yyyy-MM-dd" placeholder="请选择维保时间">
            </el-date-picker>
          </el-form-item>
           <!-- <el-form-item label="维保金额" prop="money">
                <el-input v-model="queryParams.money" placeholder="请输入维保金额"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="维保记录" prop="record">
                <el-input v-model="queryParams.record" placeholder="请输入维保记录"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="维保人" prop="userName">
                <el-input v-model="queryParams.userName" placeholder="请输入维保人"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="验收人" prop="checkName">
                <el-input v-model="queryParams.checkName" placeholder="请输入验收人"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="检修申请人" prop="jianxiuApply">
                <el-input v-model="queryParams.jianxiuApply" placeholder="请输入检修申请人"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="检修记录" prop="jianxiuRecord">
                <el-input v-model="queryParams.jianxiuRecord" placeholder="请输入检修记录"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="检修人" prop="jianxiuName">
                <el-input v-model="queryParams.jianxiuName" placeholder="请输入检修人"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
                        <el-form-item label="检修时间" prop="jianxiuDate">
                            <el-date-picker clearable v-model="queryParams.jianxiuDate"
                                            type="date" value-format="yyyy-MM-dd" placeholder="请选择检修时间">
                            </el-date-picker>
                        </el-form-item>
            <el-form-item label="更换配件" prop="peijian">
                <el-input v-model="queryParams.peijian" placeholder="请输入更换配件"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="配件费" prop="peijianMoney">
                <el-input v-model="queryParams.peijianMoney" placeholder="请输入配件费"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="合计金额" prop="allMoeny">
                <el-input v-model="queryParams.allMoeny" placeholder="请输入合计金额"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="车间主任" prop="director">
                <el-input v-model="queryParams.director" placeholder="请输入车间主任"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="主管领导" prop="leader">
                <el-input v-model="queryParams.leader" placeholder="请输入主管领导"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>-->
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                        v-hasPermi="['develop:LnShebeiWeibao:add']">新增</el-button>
            </el-col>
           <!-- <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                        @click="handleUpdate" v-hasPermi="['develop:LnShebeiWeibao:edit']">修改</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
                    <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                               v-hasPermi="['develop:LnShebeiWeibao:remove']">删除</el-button>
                </el-popconfirm>
            </el-col>-->
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini"
                        @click="handleExport" v-hasPermi="['develop:LnShebeiWeibao:export']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table" :max-height="tableMaxHeight">
            <el-table-column type="selection" width="55" align="center"/>
            <el-table-column label="设备名称" align="center" prop="name"/>
            <el-table-column label="设备编码" align="center" prop="code"/>
            <el-table-column label="设备品牌" align="center" prop="pinpai"/>
            <el-table-column label="型号" align="center" prop="xinghao"/>
            <el-table-column label="所属部门" align="center" prop="haveHouse"/>
            <el-table-column label="维保类型" align="center" prop="type"/>
            <el-table-column label="设备类型" align="center" prop="shebeiType"/>
            <el-table-column label="审核人" align="center" prop="shenheName"/>
            <el-table-column label="审核状态" align="center" prop="shenhestatus"/>
            <el-table-column label="使用部门" align="center" prop="useDept"/>
            <el-table-column label="故障问题" align="center" prop="problem"/>
            <el-table-column label="故障类别" align="center" prop="problemType"sortable>
              <template slot-scope="scope">
                <dict-tag :options="dict.type.problem_type" :value="scope.row.problemType" />
              </template>
            </el-table-column>
            <el-table-column label="维保内容" align="center" prop="maintenance"/>
            <el-table-column label="维保金额" align="center" prop="money"/>
            <el-table-column label="维保时间" align="center" prop="date" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.date, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="维保记录" align="center" prop="record"/>
            <el-table-column label="维保人" align="center" prop="userName"/>
            <el-table-column label="验收记录" align="center" prop="checkContent"/>
            <el-table-column label="验收人" align="center" prop="checkName"/>
            <el-table-column label="检修申请人" align="center" prop="jianxiuApply"/>
            <el-table-column label="检修记录" align="center" prop="jianxiuRecord"/>
            <el-table-column label="检修人" align="center" prop="jianxiuName"/>
            <el-table-column label="检修时间" align="center" prop="jianxiuDate" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.jianxiuDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="更换配件" align="center" prop="peijian"/>
            <el-table-column label="配件费" align="center" prop="peijianMoney"/>
            <el-table-column label="合计金额" align="center" prop="allMoeny"/>
            <el-table-column label="车间主任" align="center" prop="director"/>
            <el-table-column label="主管领导" align="center" prop="leader"/>
            <el-table-column label="其他文件" align="center" prop="otherFile"/>
            <el-table-column label="维修/保养文件" align="center" prop="file"/>
            <el-table-column label="备注" align="center" prop="remark"/>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit"
                            @click="handleUpdate(scope.row)" v-hasPermi="['develop:LnShebeiWeibao:edit']">修改</el-button>
                    <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                                   style="margin-left: 10px;">
                        <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                                   v-hasPermi="['develop:LnShebeiWeibao:remove']">删除</el-button>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

        <lnShebeiWeibao-form ref="form" @ok="getList"></lnShebeiWeibao-form>
    </div>
</template>

<script>
    import { deleteAction, getAction } from '@/api/manage'
    import LnShebeiWeibaoForm from '@/views/develop/lnShebeiWeibao/module/LnShebeiWeibaoForm'

    export default {
        name: "LnShebeiWeibaoList",
      dicts: ['problem_type'],
        components: {
            LnShebeiWeibaoForm,
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 设备维修保养表格数据
                dataList: [],
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
            status: null,
            name: null,
            code: null,
            pinpai: null,
            xinghao: null,
            haveHouse: null,
            otherFile: null,
            file: null,
            type: null,
            shebeiType: null,
            shenheName: null,
            shenhestatus: null,
            useDept: null,
            problem: null,
            problemType: null,
            maintenance: null,
            money: null,
            date: null,
            record: null,
            userName: null,
            checkContent: null,
            checkName: null,
            jianxiuApply: null,
            jianxiuRecord: null,
            jianxiuName: null,
            jianxiuDate: null,
            peijian: null,
            peijianMoney: null,
            allMoeny: null,
            director: null,
            leader: null
                },
                url: {
                    list:'/lnShebeiWeibao/lnShebeiWeibao/list',
                    remove:'/lnShebeiWeibao/lnShebeiWeibao/',
                    export:'/lnShebeiWeibao/lnShebeiWeibao/export',
                },
                tableMaxHeight: window.innerHeight - 320,
            };
        },
        created() {
            this.getList();
            window.addEventListener('resize', this.getTableHeight);
        },
        destroyed () {
            window.removeEventListener('resize', this.getTableHeight)
        },
        methods: {
            /** 查询设备维修保养列表 */
            getList() {
                this.loading = true;
                getAction(this.url.list, this.queryParams).then(response => {
                    this.dataList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            getTableHeight () {
                this.tableHeight = window.innerHeight - 320
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.$refs.form.handleAdd();
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.$refs.form.handleUpdate(row);
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                deleteAction(this.url.remove, ids).then(response => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => {});
            },
            /** 导出按钮操作 */
            handleExport() {
                this.download(this.url.export, {
                    ...this.queryParams
                }, `lnShebeiWeibao_${new Date().getTime()}.xlsx`)
            },
  }
};
</script>
